home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / ColorSync 2.5.1 SDK / Sample Code / CSDemo 2.5 / ShellSources / gxUtils.c < prev    next >
Encoding:
Text File  |  1998-09-09  |  4.8 KB  |  165 lines  |  [TEXT/CWIE]

  1. // Simple framework for Macintosh sample code
  2. //
  3. // David Hayward and Nick Thompson 
  4. // Developer Technical Support
  5. // AppleLink: DEVSUPPORT
  6. //
  7. // Copyrite 1995, Apple Computer,Inc
  8. //
  9. // This file contains the QuickDraw GX printing sample code, we want to have
  10. // GX analogs for all the classic printing functions, and we will have some 
  11. // additional routines in here.  This is pretty much based on the recipes in
  12. // the book Inside Macintosh QuickDraw GX: Programmers Overview
  13. // 
  14. // 10/4/94    david    first cut
  15.  
  16.  
  17. #include <Gestalt.h>
  18. #include <CodeFragments.h>
  19. #include <GXTypes.h>
  20. #include <GXGraphics.h>
  21. #include <GXEnvironment.h>
  22. #include <GXPrinting.h>
  23. #include <GXErrors.h>
  24. #include "GraphicsLibraries.h"
  25.  
  26. #include "gxGlobals.h"
  27. #include "gxUtils.h"
  28.  
  29.  
  30. /**\
  31. |**| ==============================================================================
  32. |**| PRIVATE GLOBALS
  33. |**| ==============================================================================
  34. \**/
  35. OSErr        gQDGX_present_err = 1;
  36. OSErr        gQDGX_available_err = 1;
  37. OSErr        gQDGX_initialized_err = 1;
  38.  
  39.  
  40. /**\
  41. |**| ==============================================================================
  42. |**| PUBLIC FUNCTIONS
  43. |**| ==============================================================================
  44. \**/
  45.  
  46.  
  47. /*------------------------------------------------------------------------------*\
  48.     QDGX_present
  49.  *------------------------------------------------------------------------------*
  50.         This function returns noErr if QuickDraw GX graphics and typography are present
  51.         (i.e passes gestalt) and returns an error otherwise.
  52.         It also sets the global gQDGX_present_err based on the result.
  53. \*------------------------------------------------------------------------------*/
  54. OSErr QDGX_present ( void ) 
  55. {
  56.     OSErr err;
  57.     long response;
  58.  
  59.     if ( gQDGX_present_err==noErr )
  60.         return noErr ;
  61.     
  62.     err = Gestalt(gestaltGraphicsVersion, &response) ;
  63.      
  64.     gQDGX_present_err = err;
  65.     return err;
  66. }
  67.  
  68.  
  69. /*------------------------------------------------------------------------------*\
  70.     QDGX_available
  71.  *------------------------------------------------------------------------------*
  72.         This function returns noErr if QuickDraw GX graphics and typography are available
  73.         (i.e present and initialized) to the application and returns an error otherwise.
  74.         It also sets the global gQDGX_available_err based on the return value.
  75. \*------------------------------------------------------------------------------*/
  76. OSErr QDGX_available ( void ) 
  77. {
  78.     OSErr err;
  79.  
  80.     if ( gQDGX_available_err==noErr )
  81.         return noErr;
  82.     
  83.     err = QDGX_present();
  84.     if ( !err )
  85.         err = QDGX_initialize();
  86.  
  87.     gQDGX_available_err = err;
  88.      return err ;
  89. }
  90.  
  91.  
  92. /*------------------------------------------------------------------------------*\
  93.     QDGX_initialize
  94.  *------------------------------------------------------------------------------*
  95.         This function initializes all the GX stuff.
  96.         It should be called early in the application.
  97. \*------------------------------------------------------------------------------*/
  98. OSErr QDGX_initialize ( void ) 
  99. {
  100.     OSErr err;
  101.  
  102.     if ( !gQDGX_initialized_err )
  103.         return noErr;
  104.  
  105.     err = QDGX_present();
  106.     if ( !err )
  107.     {
  108.         gQDGXClient = GXNewGraphicsClient(nil,
  109.                                         gQDGXGraphicsHeapSize * 1024L,
  110.                                         (gxClientAttribute)0L) ;
  111.         err = GXGetGraphicsError( nil ) ;
  112.     }
  113.     
  114.     if ( !err )
  115.     {
  116. #ifdef QDGXDebugging
  117.         // If gDebugging = TRUE, you will receive graphics library errors & notices will be posted.
  118.         // This functionality will only work with the "debugging" version of QuickDraw GX.  If you
  119.         // don't have the debugging version installed, these functions will not work. 
  120.         SetGraphicsLibraryErrors() ;
  121.         SetGraphicsLibraryNotices() ;    
  122. #endif
  123.  
  124. #ifdef QDGXValidation
  125.         // Set gQDGXValidation to TRUE if you want run-time validation. As you increase the amount
  126.         // of validation, The drawing speed will SLOW down due to all of the internal checking. 
  127.         // gxPublicValidation will check parameters to public routines. For additional details
  128.         // regarding the various levels of validation, see "Inside Macintosh: QuickDraw GX
  129.         // Environment and Utilties."
  130.         GXSetValidation( gxPublicValidation ) ; 
  131. #endif
  132.     }
  133.     
  134.     if ( !err )
  135.     {     // initialise the gx heap
  136.         GXEnterGraphics() ;
  137.         
  138.         // check we were ok - no errors
  139.         err = GXGetGraphicsError( nil ) ;
  140.         if (err)
  141.             GXDisposeGraphicsClient( gQDGXClient ) ;
  142.     }
  143.         
  144.     gQDGX_initialized_err = err;
  145.     return err ;
  146. }
  147.  
  148.  
  149. /*------------------------------------------------------------------------------*\
  150.     DisposeGXStuff
  151.  *------------------------------------------------------------------------------*
  152.         This function disposes all the GX stuff.
  153.         It should be called before the application exits.
  154. \*------------------------------------------------------------------------------*/
  155. void DisposeGXStuff ( void ) 
  156. {
  157.     if( !gQDGX_initialized_err )
  158.     {
  159.         GXExitGraphics() ;
  160.         GXDisposeGraphicsClient( gQDGXClient ) ;
  161.         gQDGX_initialized_err = 1;
  162.     }
  163. }
  164.  
  165.